package com.bite.common.mybatis;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.bite.common.core.constants.Constants;
import com.bite.common.core.utils.ThreadLocalUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
     this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
     //创建人，获取当前用户的id,如何调用接口获取当前用户的id?
        System.out.println(ThreadLocalUtil.get(Constants.USER_ID,Long.class));
        this.strictInsertFill(metaObject,"createBy",Long.class, ThreadLocalUtil.get(Constants.USER_ID,Long.class));

    }

    @Override
    public void updateFill(MetaObject metaObject) {
     this.strictUpdateFill(metaObject,"updateTime",LocalDateTime.class,LocalDateTime.now());
     this.strictInsertFill(metaObject,"updateBy",Long.class,ThreadLocalUtil.get(Constants.USER_ID,Long.class));
    }
}
